home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- dialog.c
-
- This module handles dialog windows.
-
- Copyright © 1994-1995, Northwestern University.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
-
- #include <Icons.h>
-
- #include "glob.h"
- #include "dialog.h"
- #include "newswatcher.h"
- #include "popuputil.h"
- #include "menus.h"
- #include "tescroll.h"
- #include "strutil.h"
- #include "text.h"
- #include "drawutil.h"
- #include "memutil.h"
- #include "windutil.h"
- #include "wind.h"
- #include "resutil.h"
- #include "teutil.h"
- #include "ic.h"
- #include "net.h"
-
-
-
- #define kNewsWatcherSmallIconID 128 /* Small program icon */
-
- #define kErrDlg 130 /* Error message dialog */
- #define kNoteDlg 141 /* Note message dialog */
- #define kCautionDlg 142 /* Caution message dialog */
- #define kErrAlert 501 /* Error message alert */
- #define kOutOfMemoryDlg 167 /* Out of memory dialog */
-
- #define kUnexpectedErrDlg 143 /* Unexpected error dialog */
-
- #define kDlgDNRErr 163 /* DNR error dialog */
- #define kDlgOpenStreamErr 164 /* Open stream error dialog */
- #define kDlgLostConnectionErr 165 /* Lost connection error dialog */
-
- #define kServerErrMessageText 129 /* Server error message TEXT resource id */
- #define kServerConnectErrMessageText 130 /* Server error msg connect TEXT rsrc id */
- #define kServerErrDlg 128 /* Server error message dialog */
- #define kServerErrScrollingTextItem 4 /* item number of scrolling text field */
-
- #define kDefaultButtonOutlineUserItemDitlID 400
-
-
-
- static Boolean gHandled; /* true if filter proc handled event */
- static short gItem; /* item number hit in filter proc, or 0 if none */
- static EventRecord *gEv; /* filter proc event record */
-
- static short gServerErrInfoType; /* index in STR# 128 resource of type of server */
- static CStr255 gServerErrInfoHost; /* server address */
-
- static TEClickLoopUPP gAutoScrollUPP;
- static ControlActionUPP gScrollActionUPP;
- static UserItemUPP gScrollingTextFieldUserItemUPP;
- static UserItemUPP gDlgDefaultButtonOutlineItemUPP;
- static AEIdleUPP gAEIdleProcUPP;
-
-
- /* The following global variables are exported. */
-
- ModalFilterUPP gDialogFilterUPP;
- UserItemUPP gDlgGrayBorderItemUPP;
-
-
-
- /*----------------------------------------------------------------------------
- DlgGetCheck
-
- Get the state of a checkbox in a dialog.
-
- Entry: dlg = pointer to dialog.
- item = item number of checkbox control.
-
- Exit: function result = true if checked, false if unchecked.
- ----------------------------------------------------------------------------*/
-
- Boolean DlgGetCheck (DialogPtr dlg, short item)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- return (GetControlValue((ControlHandle)itemHandle) == 1);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetCheck
-
- Set the state of a checkbox in a dialog.
-
- Entry: dlg = pointer to dialog.
- item = item number of checkbox control.
- value = true to check, false to uncheck.
- ----------------------------------------------------------------------------*/
-
- void DlgSetCheck (DialogPtr dlg, short item, Boolean value)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle)itemHandle, value);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgToggleCheck
-
- Toggle the state of a checkbox in a dialog.
-
- Entry: dlg = pointer to dialog.
- item = item number of checkbox control.
-
- ----------------------------------------------------------------------------*/
-
- void DlgToggleCheck (DialogPtr dlg, short item)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
- short value;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- value = (GetControlValue((ControlHandle)itemHandle) == 1) ? 0 : 1;
- SetControlValue((ControlHandle)itemHandle,value);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgGetControl
-
- Get the control handle for a dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number of control item.
-
- Exit: function result = handle to control.
- ----------------------------------------------------------------------------*/
-
- ControlHandle DlgGetControl (DialogPtr dlg, short item)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- return (ControlHandle)itemHandle;
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgGetCtlValue
-
- Get the value of a control in a dialog.
-
- Entry: dlg = pointer to dialog.
- item = item number of control.
-
- Exit: function result = value of control.
- ----------------------------------------------------------------------------*/
-
- short DlgGetCtlValue (DialogPtr dlg, short item)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- return GetControlValue((ControlHandle)itemHandle);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetCtlValue
-
- Set the value of a control in a dialog.
-
- Entry: dlg = pointer to dialog.
- item = item number of checkbox control.
- value = new control value.
- ----------------------------------------------------------------------------*/
-
- void DlgSetCtlValue (DialogPtr dlg, short item, short value)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle)itemHandle, value);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgGetNumber
-
- Get the value of a numeric dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number.
-
- Exit: function result = numeric value of item.
- ----------------------------------------------------------------------------*/
-
- long DlgGetNumber (DialogPtr dlg, short item)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
- Str255 valStr;
- long value;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- GetDialogItemText(itemHandle, valStr);
- StringToNum(valStr, &value);
- return value;
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetNumber
-
- Set the value of a numeric dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- value = new value for item.
- ----------------------------------------------------------------------------*/
-
- void DlgSetNumber (DialogPtr dlg, short item, long value)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
- Str255 valStr;
-
- NumToString(value, valStr);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- SetDialogItemText(itemHandle, valStr);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgGetCString
-
- Get the value of a string dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number.
-
- Exit: value = the string (C format).
- ----------------------------------------------------------------------------*/
-
- void DlgGetCString (DialogPtr dlg, short item, char *value)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- GetDialogItemText(itemHandle, (StringPtr)value);
- p2cstr((StringPtr)value);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetCString
-
- Set the value of a string dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- value = new string value (C format).
- ----------------------------------------------------------------------------*/
-
- void DlgSetCString (DialogPtr dlg, short item, char *value)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- c2pstr(value);
- SetDialogItemText(itemHandle, (StringPtr)value);
- p2cstr((StringPtr)value);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgGetPString
-
- Get the value of a string dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number.
-
- Exit: value = the string (Pascal format).
- ----------------------------------------------------------------------------*/
-
- void DlgGetPString (DialogPtr dlg, short item, StringPtr value)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- GetDialogItemText(itemHandle, value);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetPString
-
- Set the value of a string dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- value = new string value (Pascal format).
- ----------------------------------------------------------------------------*/
-
- void DlgSetPString (DialogPtr dlg, short item, StringPtr value)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- SetDialogItemText(itemHandle, value);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetScrollingText
-
- Set the value of a scrolling text field dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- value = pointer to first char of string.
- len = length of string.
- ----------------------------------------------------------------------------*/
-
- void DlgSetScrollingText (DialogPtr dlg, short item, char *value, short len)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TEHandle theTE;
- ControlHandle vScroll;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- theTE = (*itemInfo)[item-1].theTE;
- vScroll = (*itemInfo)[item-1].vScroll;
- TESetText(value, len, theTE);
- TEScrollScrollSelectionIntoView(theTE, vScroll);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgGetScrollingText
-
- Get the value of a scrolling text field dialog item.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- value = pointer to return buffer.
-
- Exit: *len = length of returned value.
- ----------------------------------------------------------------------------*/
-
- void DlgGetScrollingText (DialogPtr dlg, short item, char *value, short *len)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TEHandle theTE;
- Handle text;
- short teLen;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- theTE = (*itemInfo)[item-1].theTE;
- text = (**theTE).hText;
- teLen = (**theTE).teLength;
- BlockMoveData(*text, value, teLen);
- *len = teLen;
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetScrollingTextSelection
-
- Set the selection range for a scrolling text field dialog item and make
- this field the currently active one.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- selStart = start of selection range.
- selEnd = end of selection range.
- ----------------------------------------------------------------------------*/
-
- void DlgSetScrollingTextSelection (DialogPtr dlg, short item,
- short selStart, short selEnd)
- {
- DialogPeek dPeek;
- TWindow **info;
- TDialogItemInfo **itemInfo;
- short curItem, editField = 0;
- TEHandle theTE, newTE;
- ControlHandle vScroll;
-
- dPeek = (DialogPeek)dlg;
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- curItem = (**info).curItem;
- editField = dPeek->editField;
- if (curItem > 0) {
- theTE = (*itemInfo)[curItem-1].theTE;
- } else if (editField >= 0) {
- theTE = dPeek->textH;
- } else {
- theTE = nil;
- }
- if (theTE != nil) {
- TESetSelect(0, 0, theTE);
- TEDeactivate(theTE);
- }
- newTE = (*itemInfo)[item-1].theTE;
- vScroll = (*itemInfo)[item-1].vScroll;
- TEActivate(newTE);
- TESetSelect(selStart, selEnd, newTE);
- TEScrollScrollSelectionIntoView(newTE, vScroll);
- (**info).curItem = item;
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgEnableItem
-
- Enable or disable an item in a dialog box. Checks to see if the item
- is a control and calls HiliteControl if so. Also redraws the outline
- around the default button if it's what's being enabled or disabled.
-
- Entry: dlg = pointer to dialog.
- item = item number of checkbox control.
- enabled = new enabled state.
- ----------------------------------------------------------------------------*/
-
- void DlgEnableItem (DialogPtr dlg, short item, Boolean enabled)
- {
- TWindow **info;
- Handle itemHandle;
- short itemType;
- Rect box;
- Boolean oldEnable;
- GrafPtr port;
-
- GetPort(&port);
- SetPort(dlg);
-
- info = (TWindow**)GetWRefCon(dlg);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- oldEnable = (itemType & itemDisable) == 0;
- itemType = enabled ? itemType & (~itemDisable) : itemType | itemDisable;
- SetDialogItem(dlg, item, itemType, itemHandle, &box);
-
- if ((itemType & ctrlItem) != 0 && oldEnable != enabled) {
- if (item == (**info).defaultItem) {
- InsetRect(&box, -4, -4);
- InvalRect(&box);
- }
- HiliteControl((ControlHandle)itemHandle, enabled ? 0 : 255);
- }
-
- SetPort(port);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetUserItem
-
- Set the procedure for a user item in a dialog.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- proc = universal pointer to user item proc.
- ----------------------------------------------------------------------------*/
-
- void DlgSetUserItem (DialogPtr dlg, short item, UserItemUPP proc)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- SetDialogItem(dlg, item, itemType, (Handle)proc, &box);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetPict
-
- Set a dialog picture.
-
- Entry: dlg = pointer to dialog.
- item = item number of picture item.
- pict = handle to picture.
- ----------------------------------------------------------------------------*/
-
-
- void DlgSetPict (DialogPtr dlg, short item, PicHandle pict)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- SetDialogItem(dlg, item, itemType, (Handle)pict, &box);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgGrayBorderItem
-
- A user item procedure to draw a gray border around itself.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- ----------------------------------------------------------------------------*/
-
- pascal void DlgGrayBorderItem (DialogPtr dlg, short item)
- {
- Handle itemHandle;
- short itemType;
- Rect box;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- DrawGrayRect(&box);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgDefaultButtonOutlineItem
-
- A user item procedure to outline the default button.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- ----------------------------------------------------------------------------*/
-
- static pascal void DlgDefaultButtonOutlineItem (DialogPtr dlg, short item)
- {
- TWindow **info;
- Handle itemHandle;
- short itemType;
- Rect box, r;
- PenState savePen;
- short defaultItem;
- Boolean defaultOutline;
-
- info = (TWindow**)GetWRefCon(dlg);
- defaultItem = (**info).defaultItem;
- defaultOutline = (**info).defaultOutline;
- if (defaultItem == 0 || !defaultOutline) return;
- GetPenState(&savePen);
- PenNormal();
- PenSize(3, 3);
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- GetDialogItem(dlg, defaultItem, &itemType, &itemHandle, &r);
- if ((itemType & itemDisable) != 0) {
- DrawGrayRoundRect(&box, 16, 16);
- } else {
- FrameRoundRect(&box, 16, 16);
- }
- SetPenState(&savePen);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgSetDefaultButtonOutline
-
- Set whether or not the default button is outlined.
-
- Entry: dlg = pointer to dialog.
- defaultOutline = true to outline default item.
- ----------------------------------------------------------------------------*/
-
- void DlgSetDefaultButtonOutline (DialogPtr dlg, Boolean defaultOutline)
- {
- TWindow **info;
- short defaultItem;
- short itemType;
- Handle itemHandle;
- Rect box;
-
- info = (TWindow**)GetWRefCon(dlg);
- if ((**info).defaultOutline == defaultOutline) return;
- (**info).defaultOutline = defaultOutline;
- defaultItem = (**info).defaultItem;
- GetDialogItem(dlg, defaultItem, &itemType, &itemHandle, &box);
- InsetRect(&box, -4, -4);
- EraseRect(&box);
- InvalRect(&box);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DlgFlashButton
-
- Flash a button.
-
- Entry: dlg = pointer to dialog.
- item = item number of button to flash.
- ----------------------------------------------------------------------------*/
-
- void DlgFlashButton (DialogPtr dlg, short item)
- {
- short itemType;
- ControlHandle theItem;
- Rect box;
- long myticks;
-
- if (item > 0) {
- GetDialogItem(dlg, item, &itemType, (Handle*)&theItem, &box);
- HiliteControl(theItem, 1);
- Delay(8, &myticks);
- HiliteControl(theItem, 0);
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemNumeric
-
- Set the "numeric" item info.
-
- Entry: dlg = pointer to dialog.
- item = item number of textedit field.
- ----------------------------------------------------------------------------*/
-
- void SetItemNumeric (DialogPtr dlg, short item)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- Boolean *validChars;
- unsigned char c;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- (*itemInfo)[item-1].numeric = true;
- validChars = (*itemInfo)[item-1].validChars;
- memset(validChars, false, 256);
- for (c = '0'; c <= '9'; c++) validChars[c] = true;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemUSAsciiNoBlank
-
- Set the valid characters for an item to US ASCII but not a space.
-
- Entry: dlg = pointer to dialog.
- item = item number of textedit field.
- ----------------------------------------------------------------------------*/
-
- void SetItemUSAsciiNoBlank (DialogPtr dlg, short item)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- Boolean *validChars;
- unsigned char c;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- validChars = (*itemInfo)[item-1].validChars;
- memset(validChars, false, 256);
- for (c = 0x21; c <= 0x7e; c++) validChars[c] = true;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemURLSchemeName
-
- Set the valid characters for an item to alphanumerics, '+', '.', and
- '-' (the characters legal in a URL scheme name).
-
- Entry: dlg = pointer to dialog.
- item = item number of textedit field.
- ----------------------------------------------------------------------------*/
-
- void SetItemURLSchemeName (DialogPtr dlg, short item)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- Boolean *validChars;
- unsigned char c;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- validChars = (*itemInfo)[item-1].validChars;
- memset(validChars, false, 256);
- for (c = 'a'; c <= 'z'; c++) validChars[c] = true;
- for (c = 'A'; c <= 'Z'; c++) validChars[c] = true;
- for (c = '0'; c <= '9'; c++) validChars[c] = true;
- validChars['+'] = true;
- validChars['-'] = true;
- validChars['.'] = true;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemHostAddress
-
- Set the valid characters for an item to just the characters legal in
- a host address.
-
- Entry: dlg = pointer to dialog.
- item = item number of textedit field.
- ----------------------------------------------------------------------------*/
-
- void SetItemHostAddress (DialogPtr dlg, short item)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- Boolean *validChars;
- unsigned char c;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- validChars = (*itemInfo)[item-1].validChars;
- memset(validChars, false, 256);
- for (c = 'A'; c <= 'Z'; c++) validChars[c] = true;
- for (c = 'a'; c <= 'z'; c++) validChars[c] = true;
- for (c = '0'; c <= '9'; c++) validChars[c] = true;
- validChars['.'] = true;
- validChars['-'] = true;
- validChars['_'] = true;
- validChars[','] = true;
- validChars[':'] = true;
- validChars[' '] = true;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemKeyword
-
- Set the valid characters for an item to just the characters legal in
- a header keyword.
-
- Entry: dlg = pointer to dialog.
- item = item number of textedit field.
- ----------------------------------------------------------------------------*/
-
- void SetItemKeyword (DialogPtr dlg, short item)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- Boolean *validChars;
-
- SetItemUSAsciiNoBlank(dlg, item);
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- validChars = (*itemInfo)[item-1].validChars;
- validChars[':'] = false;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemPopupTypeinItem
-
- Set the "popupTypeinItem" item info.
-
- Entry: dlg = pointer to dialog.
- item = item number of popup menu control.
- popupTypeInItem = item number of corresponding typein textedit
- field, or 0 if none.
- ----------------------------------------------------------------------------*/
-
- void SetItemPopupTypeinItem (DialogPtr dlg, short item, short popupTypeinItem)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- (*itemInfo)[item-1].popupTypeinItem = popupTypeinItem;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemKeyEquivalent
-
- Set the "keyEquivalent" item info.
-
- Entry: dlg = pointer to dialog.
- item = item number of push button control.
- keyEquivalent = keyboard equivalent for control, or 0 if none.
- ----------------------------------------------------------------------------*/
-
- void SetItemKeyEquivalent (DialogPtr dlg, short item, char keyEquivalent)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- (*itemInfo)[item-1].keyEquivalent = keyEquivalent;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemMaxLength
-
- Set the "max length" item info.
-
- Entry: dlg = pointer to dialog.
- item = item number of textedit field.
- maxLength = max length of field.
- ----------------------------------------------------------------------------*/
-
- void SetItemMaxLength (DialogPtr dlg, short item, short maxLength)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- (*itemInfo)[item-1].maxLength = maxLength;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemPassword
-
- Set the "password" item info.
-
- Entry: dlg = pointer to dialog.
- item = item number of textedit field.
- password = pointer to password string, or nil if none.
- ----------------------------------------------------------------------------*/
-
- void SetItemPassword (DialogPtr dlg, short item, char *password)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- (*itemInfo)[item-1].password = password;
- }
-
-
-
- /*----------------------------------------------------------------------------
- ScrollingTextFieldUserItem
-
- The user item procedure to draw a scrolling text field.
-
- Entry: dlg = pointer to dialog.
- item = item number.
- ----------------------------------------------------------------------------*/
-
- static pascal void ScrollingTextFieldUserItem (DialogPtr dlg, short item)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- Handle itemHandle;
- short itemType;
- Rect box;
- PenState savePen;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &box);
- GetPenState(&savePen);
- PenNormal();
- PenPat(&qd.black);
- FrameRect(&box);
- SetPenState(&savePen);
-
- TEUpdate(&dlg->portRect, (*itemInfo)[item-1].theTE);
- }
-
-
-
- /*----------------------------------------------------------------------------
- AutoScroll
-
- Handle scrolling text field autoscrolling.
-
- Exit: function result = true
- ----------------------------------------------------------------------------*/
-
- static pascal Boolean AutoScroll (void)
- {
- WindowPtr wind;
- TWindow **info;
- short curItem;
- TDialogItemInfo **itemInfo;
- TDialogItemInfo *pItemInfo;
- ControlHandle vScroll;
- TEHandle theTE;
-
- wind = MyFrontWindow();
- if (wind == nil) return true;
- info = (TWindow**)GetWRefCon(wind);
- curItem = (**info).curItem;
- if (curItem == 0) return true;
- itemInfo = (**info).itemInfo;
- pItemInfo = &(*itemInfo)[curItem-1];
- vScroll = pItemInfo->vScroll;
- theTE = pItemInfo->theTE;
- TEScrollAutoScroll(theTE, vScroll);
- return true;
- }
-
-
-
- /*----------------------------------------------------------------------------
- SetItemScrollingTextField
-
- Set a scrolling text field item.
-
- Entry: dlg = pointer to dialog.
- item = item number of field.
- fontName = font name for field.
- fontSize = font size for field.
- readOnly = true if field is read only.
- ----------------------------------------------------------------------------*/
-
- void SetItemScrollingTextField (DialogPtr dlg, short item,
- StringPtr fontName, short fontSize, Boolean readOnly)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- short itemType;
- Handle itemHandle;
- Rect itemRect, teRect, sbarRect;
- TEHandle theTE;
- TextStyle savedStyle;
- FontInfo fontInfo;
- short lineHeight, numLinesInBox, boxHeight;
- ControlHandle vScroll;
- short fontNum;
- Boolean *validChars;
- GrafPtr port;
-
- GetPort(&port);
- SetPort(dlg);
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- (*itemInfo)[item-1].readOnly = readOnly;
- DlgSetUserItem(dlg, item, gScrollingTextFieldUserItemUPP);
-
- GetDialogItem(dlg, item, &itemType, &itemHandle, &itemRect);
-
- GetFontNumber(fontName, &fontNum);
-
- GetPortTextStyle(&savedStyle);
- numLinesInBox = 0;
- while (numLinesInBox < 2) {
- TextFont(fontNum);
- TextSize(fontSize);
- GetFontInfo(&fontInfo);
- lineHeight = fontInfo.ascent+fontInfo.descent+fontInfo.leading;
- numLinesInBox = (itemRect.bottom - itemRect.top - 2*kTextMargin) / lineHeight;
- if (numLinesInBox < 2) {
- if (fontSize > 12) {
- fontSize = 12;
- } else if (fontSize > 9) {
- fontSize = 9;
- } else if (fontNum != applFont) {
- fontNum = applFont;
- fontSize = 9;
- } else {
- fontSize--;
- }
- }
- }
- boxHeight = lineHeight * numLinesInBox + 2*kTextMargin;
- itemRect.bottom = itemRect.top + boxHeight;
- SetDialogItem(dlg, item, itemType, itemHandle, &itemRect);
-
- teRect = itemRect;
- teRect.right -= 16;
- InsetRect(&teRect, kTextMargin, kTextMargin);
- theTE = TENew(&teRect, &teRect);
- (**theTE).clickLoop = gAutoScrollUPP;
- (*itemInfo)[item-1].theTE = theTE;
-
- sbarRect = itemRect;
- sbarRect.left = sbarRect.right - 16;
- vScroll = NewControl(dlg, &sbarRect, "\p", true, 0, 0, 0, scrollBarProc, item);
- (*itemInfo)[item-1].vScroll = vScroll;
-
- validChars = (*itemInfo)[item-1].validChars;
- if (readOnly) {
- memset(validChars, false, 256);
- } else {
- (*itemInfo)[item-1].returnIsLegal = true;
- }
-
- SetPortTextStyle(&savedStyle);
-
- SetPort(port);
- }
-
-
-
- /*----------------------------------------------------------------------------
- NotifyUser
-
- Notify user that NewsWatcher requires attention and wait for the
- user to bring NewsWatcher to the foreground.
- ----------------------------------------------------------------------------*/
-
- void NotifyUser (void)
- {
- NMRec nRec;
- OSErr err = noErr;
- Boolean gotEvt;
- EventRecord ev;
-
- nRec.qType = nmType;
- nRec.nmMark = 1;
- err = GetIconSuite(&nRec.nmIcon, kNewsWatcherSmallIconID, svAllSmallData);
- if (err != noErr) nRec.nmIcon = nil;
- nRec.nmSound = nil;
- nRec.nmStr = nil;
- nRec.nmResp = nil;
- NMInstall(&nRec);
- while (gInBackground) {
- gotEvt = WaitNextEvent(everyEvent & ~highLevelEventMask, &ev, GetCaretTime(), nil);
- if (gotEvt) HandleEvent(&ev);
- }
- NMRemove(&nRec);
- MyDisposeHandle(nRec.nmIcon);
- }
-
-
-
- /*----------------------------------------------------------------------------
- AEIdleProc
-
- Apple event idle proc for AEInteractWithUser call.
- ----------------------------------------------------------------------------*/
-
- static pascal Boolean AEIdleProc (EventRecord *ev, long *sleep, RgnHandle *mouseRgn)
- {
- HandleEvent(ev);
- *sleep = GetCaretTime();
- *mouseRgn = nil;
- return false;
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyAEInteractWithUser
-
- Initiate user interaction during servicing of an Apple event.
-
- Exit: function result = error code (errAENoUserInteraction if
- user interaction is not allowed).
- ----------------------------------------------------------------------------*/
-
- static OSErr MyAEInteractWithUser (void)
- {
- NMRec nRec;
- OSErr err = noErr;
-
- nRec.qType = nmType;
- nRec.nmMark = 1;
- err = GetIconSuite(&nRec.nmIcon, kNewsWatcherSmallIconID, svAllSmallData);
- if (err != noErr) nRec.nmIcon = nil;
- nRec.nmSound = nil;
- nRec.nmStr = nil;
- nRec.nmResp = nil;
- err = AEInteractWithUser(kAEDefaultTimeout, &nRec, gAEIdleProcUPP);
- MyDisposeHandle(nRec.nmIcon);
- return err;
- }
-
-
-
- /*----------------------------------------------------------------------------
- PrepUserInteraction
-
- Prepare for user interaction (presenting a dialog).
-
- Exit: function result = error code (errAENoUserInteraction if we are
- serving an Apple event and user interaction is not allowed).
- ----------------------------------------------------------------------------*/
-
- OSErr PrepUserInteraction (void)
- {
- WindowPtr wind;
- OSErr err = noErr;
-
- wind = MyFrontWindow();
- if (GetMyWindowKind(wind) == kStatus) DoClose(wind);
- if (gAEServer) {
- err = MyAEInteractWithUser();
- if (err != noErr) return err;
- } else {
- if (gInBackground) NotifyUser();
- }
- SetCursor(&qd.arrow);
- HiliteMenu(0);
- gInDialog = true;
- return noErr;
- }
-
-
-
- /*----------------------------------------------------------------------------
- InitDefaultIteminfo
-
- Initialize default item info.
-
- Entry: x = pointer to item info.
- ----------------------------------------------------------------------------*/
-
- static void InitDefaultItemInfo (TDialogItemInfo *x)
- {
- short c;
-
- x->numeric = false;
- x->returnIsLegal = false;
- x->popupTypeinItem = 0;
- x->keyEquivalent = 0;
- x->maxLength = 0x7fff;
- x->password = nil;
- x->readOnly = false;
- x->theTE = nil;
- x->vScroll = nil;
- for (c = 0; c <= 255; c++) x->validChars[c] = isPrintable(c);
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyGetNewDialog
-
- Get a new dialog and intialize the dialog information.
-
- Entry: id = resource id of DLOG resource.
- defaultItem = item number of default button, or 0 if none.
- cancelItem = item number of cancel button, or 0 if none.
-
- Exit: function result = error code.
- *theDialog = pointer to dialog record.
- ----------------------------------------------------------------------------*/
-
- OSErr MyGetNewDialog (short id, short defaultItem, short cancelItem,
- DialogPtr *theDialog)
- {
- DialogTemplate **template;
- Boolean movableModal;
- DialogPtr dlg = nil;
- TWindow **info = nil;
- TDialogItemInfo **itemInfo = nil;
- TDialogItemInfo x;
- short numItems, i;
- Handle outlineDitl;
- short itemType;
- Handle itemHandle;
- Rect itemRect, defaultRect;
- OSErr err = noErr;
- Boolean savedCriticalSeq;
-
- BeginCriticalMemorySequence(&savedCriticalSeq);
- err = MyGetResource('DLOG', id, &template);
- if (err != noErr) goto exit;
- movableModal = (**template).procID == movableDBoxProc;
- err = PrepUserInteraction();
- if (err != noErr) goto exit;
- dlg = GetNewDialog(id, nil, (WindowPtr)-1);
- if (defaultItem != 0) {
- err = MyGetResource('DITL', kDefaultButtonOutlineUserItemDitlID, &outlineDitl);
- if (err != noErr) goto exit;
- AppendDITL(dlg, outlineDitl, overlayDITL);
- numItems = CountDITL(dlg);
- GetDialogItem(dlg, defaultItem, &itemType, &itemHandle, &defaultRect);
- GetDialogItem(dlg, numItems, &itemType, &itemHandle, &itemRect);
- InsetRect(&defaultRect, -4, -4);
- SetDialogItem(dlg, numItems, itemType,
- (Handle)gDlgDefaultButtonOutlineItemUPP, &defaultRect);
- }
- err = MyNewHandle(sizeof(TWindow), &info);
- if (err != noErr) goto exit;
- SetWRefCon(dlg, (long)info);
- numItems = CountDITL(dlg);
- err = MyNewHandle(numItems * sizeof(TDialogItemInfo), &itemInfo);
- if (err != noErr) goto exit;
- (**info).kind = kDialog;
- (**info).movableModal = movableModal;
- (**info).defaultItem = defaultItem;
- (**info).defaultOutline = true;
- (**info).cancelItem = cancelItem;
- (**info).curItem = 0;
- (**info).itemInfo = itemInfo;
- InitDefaultItemInfo(&x);
- for (i = 0; i < numItems; i++) (*itemInfo)[i] = x;
- SetMenusTo(movableModal ? kAppleOnlyAboutDisabled : kAppleAllDisabled, 0, 0, 0, 0, 0);
- HiliteMenu(0);
- *theDialog = dlg;
- gMyCurDialog = dlg;
- EndCriticalMemorySequence(savedCriticalSeq);
- return noErr;
-
- exit:
-
- if (dlg != nil) DisposeDialog(dlg);
- MyDisposeHandle(info);
- MyDisposeHandle(itemInfo);
- EndCriticalMemorySequence(savedCriticalSeq);
- gMyCurDialog = nil;
- return err;
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyShortenDITL
-
- Shorten a dialog's item list.
-
- Entry: dlg = pointer to dialog.
- numberItems = number of items to remove from the dialog item list.
- ----------------------------------------------------------------------------*/
-
- void MyShortenDITL (DialogPtr dlg, short numberItems)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TDialogItemInfo *pItemInfo;
- short numItems, item;
- char state;
-
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- numItems = CountDITL(dlg);
- state = MyHGetState(itemInfo);
- MyHLock(itemInfo);
- for (item = numItems - numberItems + 1, pItemInfo = *itemInfo + item - 1;
- item <= numItems;
- item++, pItemInfo++)
- {
- if (pItemInfo->theTE != nil) TEDispose(pItemInfo->theTE);
- if (pItemInfo->vScroll != nil) DisposeControl(pItemInfo->vScroll);
- }
- MyHSetState(itemInfo, state);
- ShortenDITL(dlg, numberItems);
- numItems = CountDITL(dlg);
- if ((**info).curItem > numItems) (**info).curItem = 0;
- MySetHandleSize(itemInfo, numItems*sizeof(TDialogItemInfo));
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyAppendDITL
-
- Add items to a dialog's item list.
-
- Entry: dlg = pointer to dialog.
- theDITL = handle to item list to append.
- theMethod = the manner in which the new items should be displayed,
- as in the Dialog Manger AppendDITL procedure.
-
- Exit: function result = error code.
- ----------------------------------------------------------------------------*/
-
- OSErr MyAppendDITL (DialogPtr dlg, Handle theDITL, DITLMethod theMethod)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TDialogItemInfo x;
- short oldNumItems, numItems, i;
- OSErr err = noErr;
-
- oldNumItems = CountDITL(dlg);
- AppendDITL(dlg, theDITL, theMethod);
- info = (TWindow**)GetWRefCon(dlg);
- itemInfo = (**info).itemInfo;
- numItems = CountDITL(dlg);
- err = MySetHandleSizeCritical(itemInfo, numItems*sizeof(TDialogItemInfo));
- if (err != noErr) return err;
- InitDefaultItemInfo(&x);
- for (i = oldNumItems; i < numItems; i++) (*itemInfo)[i] = x;
- return noErr;
- }
-
-
-
- /*----------------------------------------------------------------------------
- ScrollAction
-
- Vertical scroll bar action proc.
-
- Entry: vScroll = handle to vertical scroll bar control.
- part = part code.
- ----------------------------------------------------------------------------*/
-
- static pascal void ScrollAction (ControlHandle vScroll, short part)
- {
- WindowPtr wind;
- TWindow **info;
- TDialogItemInfo **itemInfo;
- short item;
- TEHandle theTE;
-
- wind = (**vScroll).contrlOwner;
- info = (TWindow**)GetWRefCon(wind);
- itemInfo = (**info).itemInfo;
- item = GetControlReference(vScroll);
- theTE = (*itemInfo)[item-1].theTE;
- SetControlReference(vScroll, 0);
- TEScrollScrollByPartCode(theTE, vScroll, part);
- SetControlReference(vScroll, item);
- }
-
-
-
- /*----------------------------------------------------------------------------
- DialogFilter
-
- Universal modal dialog filter.
-
- Entry: dlg = pointer to dialog.
- ev = pointer to event record.
-
- Exit: function result = true if event handled and item hit.
- *itemHit = item number of item hit.
- ev = pointer to possibly modified event record.
- ----------------------------------------------------------------------------*/
-
- pascal Boolean DialogFilter (DialogPtr dlg, EventRecord *ev, short *itemHit)
- {
- static RgnHandle cursorRgn = nil;
- short itemType;
- Handle itemHandle;
- Rect box;
-
- if (ev->what != nullEvent) {
- gPrevEvent = gCurEvent;
- gCurEvent = *ev;
- }
-
- if (cursorRgn == nil) cursorRgn = NewRgn();
- HandleIdle(cursorRgn);
-
- gHandled = false;
- gItem = 0;
- gEv = ev;
-
- if (ev->what == updateEvt && (WindowPtr)ev->message == dlg) return false;
- if (ev->what == updateEvt || ev->what == activateEvt) gHandled = true;
-
- HandleEvent(ev);
-
- if (gItem != 0) {
- GetDialogItem(dlg, gItem, &itemType, &itemHandle, &box);
- if ((itemType & itemDisable) != 0) {
- ev->what = nullEvent;
- return false;
- } else {
- *itemHit = gItem;
- return true;
- }
- } else if (gHandled) {
- ev->what = nullEvent;
- return false;
- } else {
- return false;
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyModalDialog
-
- Present a modal dialog.
-
- Entry: dlg = pointer to dialog window.
- filterProc = filter proc UPP.
-
- Exit: *itemHit = item number hit.
- ----------------------------------------------------------------------------*/
-
- void MyModalDialog (DialogPtr dlg, ModalFilterUPP filterProc, short *itemHit)
- {
- MyShowWindow(dlg);
- ModalDialog(filterProc, itemHit);
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyMovableModalDialog
-
- Present a movable modal dialog.
-
- Entry: dlg = pointer to dialog window.
- filterProc = filter proc UPP.
-
- Exit: *itemHit = item number hit.
- ----------------------------------------------------------------------------*/
-
- void MyMovableModalDialog (DialogPtr dlg, ModalFilterProcPtr filterProc, short *itemHit)
- {
- EventRecord ev;
- Boolean gotEvt;
- DialogPtr tempDlg;
- GrafPtr port;
-
- GetPort(&port);
- SetPort(dlg);
-
- MyShowWindow(dlg);
-
- while (true) {
- gotEvt = WaitNextEvent(everyEvent & ~highLevelEventMask, &ev, 0, nil);
- if (!gotEvt) ev.what = nullEvent;
- if ((*filterProc)(dlg, &ev, itemHit)) goto exit;
- if (!gHandled && IsDialogEvent(&ev) &&
- DialogSelect(&ev, &tempDlg, itemHit)) goto exit;
- }
-
- exit:
-
- SetPort(port);
-
- }
-
-
-
- /*----------------------------------------------------------------------------
- ErrorMessage
-
- Issue an error message alert.
-
- Entry: msg = error message.
- ----------------------------------------------------------------------------*/
-
- void ErrorMessage (char *msg)
- {
- DialogPtr dlg;
- short item;
- OSErr err = noErr;
-
- c2pstr(msg);
- ParamText((StringPtr)msg, "\p", "\p", "\p");
- p2cstr((StringPtr)msg);
- err = MyGetNewDialog(kErrDlg, ok, 0, &dlg);
- SysBeep(0);
- if (err != noErr) return;
- MyModalDialog(dlg, gDialogFilterUPP, &item);
- DoClose(dlg);
- }
-
-
-
- /*----------------------------------------------------------------------------
- ErrorMessageNumber
-
- Issue an error message alert.
-
- Entry: index = index in STR# 128 resource of error message.
- ----------------------------------------------------------------------------*/
-
- void ErrorMessageNumber (short index)
- {
- CStr255 msg;
-
- GetCString(index, msg);
- ErrorMessage(msg);
- }
-
-
-
- /*----------------------------------------------------------------------------
- NoteMessage
-
- Issue a note message alert.
-
- Entry: msg = note message.
- ----------------------------------------------------------------------------*/
-
- void NoteMessage (char *msg)
- {
- DialogPtr dlg;
- short item;
- OSErr err;
-
- c2pstr(msg);
- ParamText((StringPtr)msg, "\p", "\p", "\p");
- p2cstr((StringPtr)msg);
- err = MyGetNewDialog(kNoteDlg, ok, 0, &dlg);
- SysBeep(0);
- if (err != noErr) return;
- MyModalDialog(dlg, gDialogFilterUPP, &item);
- DoClose(dlg);
- }
-
-
-
- /*----------------------------------------------------------------------------
- NoteMessageNumber
-
- Issue a note message alert.
-
- Entry: index = index in STR# 128 resource of note message.
- ----------------------------------------------------------------------------*/
-
- void NoteMessageNumber (short index)
- {
- CStr255 msg;
-
- GetCString(index, msg);
- NoteMessage(msg);
- }
-
-
-
- /*----------------------------------------------------------------------------
- CautionMessage
-
- Issue a caution message alert.
-
- Entry: msg = caution message.
- ----------------------------------------------------------------------------*/
-
- void CautionMessage (char *msg)
- {
- DialogPtr dlg;
- short item;
- OSErr err = noErr;
-
- c2pstr(msg);
- ParamText((StringPtr)msg, "\p", "\p", "\p");
- p2cstr((StringPtr)msg);
- err = MyGetNewDialog(kCautionDlg, ok, 0, &dlg);
- SysBeep(0);
- if (err != noErr) return;
- MyModalDialog(dlg, gDialogFilterUPP, &item);
- DoClose(dlg);
- }
-
-
-
- /*----------------------------------------------------------------------------
- CautionMessageNumber
-
- Issue a caution message alert.
-
- Entry: index = index in STR# 128 resource of caution message.
- ----------------------------------------------------------------------------*/
-
- void CautionMessageNumber (short index)
- {
- CStr255 msg;
-
- GetCString(index, msg);
- CautionMessage(msg);
- }
-
-
-
- /*----------------------------------------------------------------------------
- StopAlertMessage
-
- Issue an error message alert from a dialog.
-
- Entry: msg = error message.
- ----------------------------------------------------------------------------*/
-
- void StopAlertMessage (char *msg)
- {
- c2pstr(msg);
- ParamText((StringPtr)msg, "\p", "\p", "\p");
- p2cstr((StringPtr)msg);
- StopAlert(kErrAlert, nil);
- }
-
-
-
- /*----------------------------------------------------------------------------
- StopAlertNumber
-
- Issue an error message alert from a dialog.
-
- Entry: index = index in STR# 128 resource of error message.
- ----------------------------------------------------------------------------*/
-
- void StopAlertNumber (short index)
- {
- CStr255 msg;
-
- GetCString(index, msg);
- StopAlertMessage(msg);
- }
-
-
-
- /*----------------------------------------------------------------------------
- CautionAlertMessage
-
- Issue a caution message alert from a dialog.
-
- Entry: msg = error message.
- ----------------------------------------------------------------------------*/
-
- void CautionAlertMessage (char *msg)
- {
- c2pstr(msg);
- ParamText((StringPtr)msg, "\p", "\p", "\p");
- p2cstr((StringPtr)msg);
- CautionAlert(kErrAlert, nil);
- }
-
-
-
- /*----------------------------------------------------------------------------
- CautionAlertNumber
-
- Issue a caution message alert from a dialog.
-
- Entry: index = index in STR# 128 resource of error message.
- ----------------------------------------------------------------------------*/
-
- void CautionAlertNumber (short index)
- {
- CStr255 msg;
-
- GetCString(index, msg);
- CautionAlertMessage(msg);
- }
-
-
-
- /*----------------------------------------------------------------------------
- ReportSystemError
-
- Report a system error.
-
- Entry: err = error number.
- ----------------------------------------------------------------------------*/
-
- void ReportSystemError (OSErr err)
- {
- Str255 errNumStr;
- DialogPtr dlg;
- short item, id;
- Str255 serverType;
-
- switch (err) {
- case noErr:
- case userCanceledErr:
- case iPrAbort:
- return;
- case memFullErr:
- err = MyGetNewDialog(kOutOfMemoryDlg, ok, 0, &dlg);
- SysBeep(0);
- if (err != noErr) return;
- MyModalDialog(dlg, gDialogFilterUPP, &item);
- DoClose(dlg);
- return;
- case netOpenDriverErr:
- ErrorMessageNumber(NetHaveOT() ? kStrCouldNotOpenOT :
- kStrCouldNotOpenMacTCP);
- return;
- case netDNRErr:
- case netOpenStreamErr:
- case netLostConnectionErr:
- switch (err) {
- case netDNRErr:
- id = kDlgDNRErr;
- break;
- case netOpenStreamErr:
- id = kDlgOpenStreamErr;
- break;
- case netLostConnectionErr:
- id = kDlgLostConnectionErr;
- break;
- }
- GetPString(gServerErrInfoType, serverType);
- c2pstr(gServerErrInfoHost);
- ParamText(serverType, (StringPtr)gServerErrInfoHost, "\p", "\p");
- err = MyGetNewDialog(id, ok, 0, &dlg);
- SysBeep(0);
- if (err != noErr) return;
- MyModalDialog(dlg, gDialogFilterUPP, &item);
- DoClose(dlg);
- return;
- case dirFulErr:
- ErrorMessageNumber(kStrDirFull);
- return;
- case dskFulErr:
- ErrorMessageNumber(kStrDiskFull);
- return;
- case ioErr:
- ErrorMessageNumber(kStrDiskIOErr);
- return;
- case opWrErr:
- case fLckdErr:
- case fBsyErr:
- case permErr:
- case wrPermErr:
- ErrorMessageNumber(kStrFileLockedOrBusy);
- return;
- case vLckdErr:
- ErrorMessageNumber(kStrVolLocked);
- return;
- case wPrErr:
- ErrorMessageNumber(kStrDiskWriteProtected);
- return;
- default:
- NumToString(err, errNumStr);
- ParamText(errNumStr, "\p", "\p", "\p");
- err = MyGetNewDialog(kUnexpectedErrDlg, ok, 0, &dlg);
- SysBeep(0);
- if (err != noErr) return;
- MyModalDialog(dlg, gDialogFilterUPP, &item);
- DoClose(dlg);
- return;
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- SaveNetErrorInfo
-
- Save information for a network error message.
-
- Entry: index = index in STR# of server type ("news", "mail", or "FTP").
- host = address of server host, as a C-format string.
- ----------------------------------------------------------------------------*/
-
- void SaveNetErrorInfo (short index, char *host)
- {
- gServerErrInfoType = index;
- strcpy(gServerErrInfoHost, host);
- }
-
-
-
- /*----------------------------------------------------------------------------
- ServerErrorMessage
-
- Issue a server error message.
-
- Entry: index = index in STR# of server type ("news", "mail", or "FTP").
- command = the command NewsWatcher tried to send to the server,
- or nil if none (connect error).
- response = error message as returned by the server.
-
- Exit: function result = error code.
- ----------------------------------------------------------------------------*/
-
- OSErr ServerErrorMessage (short index, char *command, char *response)
- {
- CStr255 cmd, serverType;
- Handle msg = nil;
- Str255 errMsg;
- char *p;
- short len;
- DialogPtr dlg = nil;
- short item;
- OSErr err = noErr;
-
- MyICReadSharedPrefs(kICScreenFont);
-
- GetCString(index, serverType);
-
- if (command == nil) {
- strcpy(cmd, " ");
- } else if (MyStrNEqual(command, "PASS", 4)) {
- strcpy(cmd, "PASS *******");
- } else if (MyStrNEqual(command, "AUTHINFO PASS", 13)) {
- strcpy(cmd, "AUTHINFO PASS *******");
- } else {
- strcpy(cmd, command);
- }
-
- p = response;
- while (*p == ' ') p++;
- while (isdigit(*p)) p++;
- while (*p == ' ') p++;
- len = strlen(p);
- BlockMoveData(p, errMsg+1, len);
- *errMsg = len;
-
- if (*cmd == 0) {
- err = MyGetResource('TEXT', kServerConnectErrMessageText, &msg);
- if (err != noErr) goto exit;
- Munger(msg, 0, "^0", 2, serverType, strlen(serverType));
- Munger(msg, 0, "^1", 2, response, strlen(response));
- } else {
- err = MyGetResource('TEXT', kServerErrMessageText, &msg);
- if (err != noErr) goto exit;
- Munger(msg, 0, "^0", 2, serverType, strlen(serverType));
- Munger(msg, 0, "^1", 2, cmd, strlen(cmd));
- Munger(msg, 0, "^2", 2, response, strlen(response));
- }
-
- SysBeep(0);
- err = MyGetNewDialog(kServerErrDlg, ok, 0, &dlg);
- if (err != noErr) goto exit;
- RestoreMovableModalDialogPosition(dlg, gPrefs.servErrLoc);
- ParamText(errMsg, "\p", "\p", "\p");
- SetItemScrollingTextField(dlg, kServerErrScrollingTextItem,
- gPrefs.textFont, gPrefs.textSize, true);
- MyHLock(msg);
- DlgSetScrollingText(dlg, kServerErrScrollingTextItem, *msg,
- MyGetHandleSize(msg));
- MyReleaseResource(msg);
- DlgSetScrollingTextSelection(dlg, kServerErrScrollingTextItem, 0, 0);
- MyMovableModalDialog(dlg, DialogFilter, &item);
- SaveMovableModalDialogPosition(dlg, &gPrefs.servErrLoc);
- return DoClose(dlg);
-
- exit:
-
- if (dlg != nil) DisposeDialog(dlg);
- if (msg != nil) MyReleaseResource(msg);
- return err;
- }
-
-
-
- /*----------------------------------------------------------------------------
- RestoreMovableModalDialogPosition
-
- Restore the saved position of a movable modal dialog window.
-
- Entry: dlg = pointer to dialog window.
- pos = saved position in global coordinates.
- ----------------------------------------------------------------------------*/
-
- void RestoreMovableModalDialogPosition (DialogPtr dlg, Point pos)
- {
- GrafPtr port;
- Point defaultLocn;
-
- GetPort(&port);
- SetPort(dlg);
- if (pos.h != 0 || pos.v != 0) {
- SetPt(&defaultLocn, 0, 0);
- LocalToGlobal(&defaultLocn);
- MoveWindow(dlg, pos.h, pos.v, false);
- if (!WindOnScreen(dlg)) MoveWindow(dlg, defaultLocn.h, defaultLocn.v, false);
- }
- SetPort(port);
- }
-
-
-
- /*----------------------------------------------------------------------------
- SaveMovableModalDialogPosition
-
- Save the position of a movable modal dialog window.
-
- Entry: dlg = pointer to dialog window.
-
- Exit: *pos = saved position in global coordinates.
- ----------------------------------------------------------------------------*/
-
- void SaveMovableModalDialogPosition (DialogPtr dlg, Point *pos)
- {
- GrafPtr port;
-
- GetPort(&port);
- SetPort(dlg);
- SetPt(pos, 0, 0);
- LocalToGlobal(pos);
- SetPort(port);
- }
-
-
-
- /*----------------------------------------------------------------------------
- Activate
-
- Handle an activate event for a dialog window.
-
- Entry: wind = pointer to dialog window.
- act = true to activate, false to deactivate
- ----------------------------------------------------------------------------*/
-
- static void Activate (WindowPtr wind, Boolean act)
- {
- DialogPeek dPeek;
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TEHandle theTE;
- short curItem, editField = 0;
-
- dPeek = (DialogPeek)wind;
- info = (TWindow**)GetWRefCon(wind);
- itemInfo = (**info).itemInfo;
- curItem = (**info).curItem;
- if (curItem > 0) {
- editField = curItem;
- theTE = (*itemInfo)[curItem-1].theTE;
- } else {
- editField = dPeek->editField + 1;
- theTE = dPeek->textH;
- }
- if (editField > 0) {
- if (act) {
- TEActivate(theTE);
- } else {
- TEDeactivate(theTE);
- }
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- Update
-
- Handle an update event for a dialog window.
-
- Entry: wind = pointer to dialog window.
- ----------------------------------------------------------------------------*/
-
- static void Update (WindowPtr wind)
- {
- UpdateDialog(wind, wind->visRgn);
- }
-
-
-
- /*----------------------------------------------------------------------------
- Mouse
-
- Handle a mouse down event in the content area of a dialog window.
-
- Entry: wind = pointer to dialog window.
- where = location of mouse down in local coords.
- modifiers = modifiers field from event record.
-
- Exit: function result = error code.
- ----------------------------------------------------------------------------*/
-
- static OSErr Mouse (WindowPtr wind, Point where, short modifiers)
- {
- DialogPeek dPeek;
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TDialogItemInfo *pItemInfo;
- TEHandle theTE, curTE;
- ControlHandle vScroll, popupCtl, control;
- Str255 str;
- short item, popupTypeinItem, part, oldVal, dv;
- Boolean numeric;
- Rect box, viewRect;
- Handle itemHandle;
- short itemType, curItem;
- short selStart, selEnd, editField;
-
- dPeek = (DialogPeek)wind;
- info = (TWindow**)GetWRefCon(wind);
- itemInfo = (**info).itemInfo;
- curItem = (**info).curItem;
- if (curItem > 0) {
- editField = curItem;
- curTE = (*itemInfo)[curItem-1].theTE;
- } else if (dPeek->editField >= 0) {
- editField = dPeek->editField + 1;
- curTE = dPeek->textH;
- } else {
- curTE = nil;
- }
-
- item = FindDialogItem(wind, where) + 1;
-
- if (item <= 0) {
- gHandled = true;
- return noErr;
- }
-
- pItemInfo = &(*itemInfo)[item-1];
- popupTypeinItem = pItemInfo->popupTypeinItem;
- theTE = pItemInfo->theTE;
- vScroll = pItemInfo->vScroll;
- GetDialogItem(wind, item, &itemType, &itemHandle, &box);
-
- if (popupTypeinItem != 0) {
- if (curTE != nil) {
- selStart = (**curTE).selStart;
- selEnd = (**curTE).selEnd;
- }
- SelectDialogItemText(wind, popupTypeinItem, 0, 0x7fff);
- DlgGetPString(wind, popupTypeinItem, str);
- popupCtl = DlgGetControl(wind, item);
- numeric = (*itemInfo)[popupTypeinItem-1].numeric;
- if (TrackPopup(popupCtl, where, str, numeric)) {
- gItem = item;
- GetPopupPString(popupCtl, kCurrentPopupItem, str);
- DlgSetPString(wind, popupTypeinItem, str);
- if (curTE != nil) {
- if (editField == popupTypeinItem) {
- SelectDialogItemText(wind, popupTypeinItem, 0, 0x7fff);
- } else if (curItem == 0) {
- SelectDialogItemText(wind, editField, selStart, selEnd);
- } else {
- theTE = dPeek->textH;
- TESetSelect(0, 0, theTE);
- TEDeactivate(theTE);
- }
- }
- }
- gHandled = true;
- return noErr;
- }
-
- if (theTE != nil) {
- part = FindControl(where, wind, &control);
- viewRect = (**theTE).viewRect;
- if ((part != 0 && control == vScroll) || PtInRect(where, &viewRect)) {
- if (curItem != item) {
- if (curTE != nil) {
- TESetSelect(0, 0, curTE);
- TEDeactivate(curTE);
- if ((**curTE).teLength == 0) {
- /* Goofy hack to erase insertion point when tabbing from an
- empty field right after a window activate. Don't know why
- this is required, but it is. */
- box = (**curTE).viewRect;
- EraseRect(&box);
- }
- }
- TEActivate(theTE);
- (**info).curItem = item;
- }
- if (part != 0) {
- if (part == inThumb) {
- oldVal = GetControlValue(vScroll);
- TrackControl(vScroll, where, nil);
- dv = GetControlValue(vScroll) - oldVal;
- if (dv != 0) TEScrollScrollText(theTE, vScroll, -dv);
- } else {
- TrackControl(vScroll, where, gScrollActionUPP);
- TEScrollAdjustScrollMax(theTE, vScroll);
- }
- } else {
- if (curItem == item) {
- MyTEClick(where, (modifiers & shiftKey) != 0, theTE);
- } else {
- MyTEClick(where, 0, theTE);
- }
- }
- gHandled = true;
- return noErr;
- }
- }
-
- if (curItem > 0 && (itemType & 0x7f) == editText && curTE != nil) {
- TESetSelect(0, 0, curTE);
- TEDeactivate(curTE);
- (**info).curItem = 0;
- TEActivate(dPeek->textH);
- }
-
- return noErr;
- }
-
-
-
- /*----------------------------------------------------------------------------
- Draggable
-
- Determine whether a mouse down event is on a draggable object in a
- dialog window.
-
- Entry: wind = pointer to dialog window.
- where = location of mouse down event, in local coordinates.
- modifiers = modifiers field from event record.
-
- Exit: function result = true if object is draggable.
- ----------------------------------------------------------------------------*/
-
- static Boolean Draggable (WindowPtr wind, Point where, short modifiers)
- {
- return false;
- }
-
-
-
- /*----------------------------------------------------------------------------
- Key
-
- Handle a key down event for a dialog window.
-
- Entry: wind = pointer to dialog window.
- theChar = ASCII code of key.
- theKey = keyboard code of key.
- modifiers = modifiers field from event record.
-
- Exit: function result = error code.
- ----------------------------------------------------------------------------*/
-
- static OSErr Key (WindowPtr wind, unsigned char theChar, unsigned char theKey, short modifiers)
- {
- DialogPeek dPeek;
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TDialogItemInfo *pItemInfo;
- TEHandle theTE = nil, newTE;
- Boolean command, returnIsLegal = false, readOnly, isArrow;
- char *password;
- short itemType, item, numItems, editField = 0, newEditField;
- short selStart, selEnd, maxLength, pwLen;
- Handle itemHandle;
- Rect r;
- short curItem;
- ControlHandle vScroll;
- short delta;
- Boolean validChar;
- short defaultItem, cancelItem;
- char state;
- Boolean extraSpaceDeleted;
- short scrollIntoView;
-
- dPeek = (DialogPeek)wind;
- info = (TWindow**)GetWRefCon(wind);
- defaultItem = (**info).defaultItem;
- cancelItem = (**info).cancelItem;
- itemInfo = (**info).itemInfo;
- curItem = (**info).curItem;
- if (curItem > 0) {
- editField = curItem;
- theTE = (*itemInfo)[curItem-1].theTE;
- } else {
- editField = dPeek->editField + 1;
- theTE = dPeek->textH;
- }
- numItems = **(short**)(dPeek->items) + 1;
- if (editField > 0) {
- selStart = (**theTE).selStart;
- selEnd = (**theTE).selEnd;
- pItemInfo = &(*itemInfo)[editField-1];
- returnIsLegal = pItemInfo->returnIsLegal;
- maxLength = pItemInfo->maxLength;
- password = pItemInfo->password;
- readOnly = pItemInfo->readOnly;
- vScroll = pItemInfo->vScroll;
- validChar = pItemInfo->validChars[theChar];
- if (password != nil) pwLen = strlen(password);
- }
-
- isArrow = IsArrowKey(theChar);
- command = (modifiers & cmdKey) != 0;
-
- if (defaultItem != 0 && !command &&
- (theChar == returnKey && !returnIsLegal || theChar == enterKey))
- {
- GetDialogItem(wind, defaultItem, &itemType, &itemHandle, &r);
- if ((itemType & itemDisable) == 0) {
- gItem = defaultItem;
- DlgFlashButton(wind, defaultItem);
- } else {
- gHandled = true;
- }
- return noErr;
- }
-
- if (cancelItem != 0 && ((!command && theKey == escapeKeyCode) ||
- (command && theChar == '.')))
- {
- GetDialogItem(wind, cancelItem, &itemType, &itemHandle, &r);
- if ((itemType & itemDisable) == 0) {
- gItem = cancelItem;
- DlgFlashButton(wind, cancelItem);
- } else {
- gHandled = true;
- }
- return noErr;
- }
-
- if (!isArrow && (command || editField == 0)) {
- state = MyHGetState(itemInfo);
- MyHLock(itemInfo);
- for (item = 1, pItemInfo = *itemInfo;
- item <= numItems;
- item++, pItemInfo++)
- {
- if (tolower(theChar) == tolower(pItemInfo->keyEquivalent)) {
- GetDialogItem(wind, item, &itemType, &itemHandle, &r);
- if ((itemType & itemDisable) == 0) {
- gItem = item;
- DlgFlashButton(wind, item);
- }
- break;
- }
- }
- gHandled = true;
- MyHSetState(itemInfo, state);
- return noErr;
- }
-
- if (command) {
- SysBeep(0);
- return noErr;
- }
-
- if (editField == 0) return noErr;
-
- if (theKey == clearKeyCode) gEv->message = theChar = deleteKey;
-
- if (theChar == tabKey) {
- delta = (modifiers & shiftKey) != 0 ? -1 : +1;
- newEditField = editField + delta;
- while (newEditField != editField) {
- if (newEditField > numItems) newEditField = 1;
- if (newEditField <= 0) newEditField = numItems;
- GetDialogItem(wind, newEditField, &itemType, &itemHandle, &r);
- newTE = (*itemInfo)[newEditField-1].theTE;
- if ((itemType & 0x7f) == editText) {
- TESetSelect(0, 0, theTE);
- TEDeactivate(theTE);
- (**info).curItem = 0;
- SelectDialogItemText(wind, newEditField, 0, 0x7fff);
- break;
- } else if (newTE != nil) {
- TESetSelect(0, 0, theTE);
- TEDeactivate(theTE);
- if ((**theTE).teLength == 0) {
- /* Goofy hack to erase insertion point when tabbing from an
- empty field right after a window activate. Don't know why
- this is required, but it is. */
- r = (**theTE).viewRect;
- EraseRect(&r);
- }
- (**info).curItem = newEditField;
- TESetSelect(0, 0x7fff, newTE);
- TEActivate(newTE);
- break;
- }
- newEditField += delta;
- }
- gHandled = true;
- return noErr;
- }
-
- if (curItem > 0) {
- if (theChar == pageUpKey) {
- TEScrollScrollByPartCode(theTE, vScroll, inPageUp);
- gHandled = true;
- return noErr;
- }
- if (theChar == pageDownKey) {
- TEScrollScrollByPartCode(theTE, vScroll, inPageDown);
- gHandled = true;
- return noErr;
- }
- if (theChar == homeKey) {
- TEScrollScrollByPartCode(theTE, vScroll, kScrollToHome);
- gHandled = true;
- return noErr;
- }
- if (theChar == endKey) {
- TEScrollScrollByPartCode(theTE, vScroll, kScrollToEnd);
- gHandled = true;
- return noErr;
- }
- }
-
- if (theChar == forwardDelKey && !readOnly) {
- if (selStart < selEnd) {
- theChar = deleteKey;
- } else if (selEnd < (**theTE).teLength) {
- selEnd++;
- (**theTE).selEnd = selEnd;
- TEDelete(theTE);
- if (password != nil)
- BlockMoveData(password + selEnd, password + selStart, pwLen - selEnd + 1);
- gItem = editField;
- gHandled = true;
- return noErr;
- } else {
- gHandled = true;
- return noErr;
- }
- }
-
- if (theChar == deleteKey && selStart < selEnd && password == nil) {
- MyTEDelete(theTE, false, &extraSpaceDeleted);
- if (curItem > 0) TEScrollScrollSelectionIntoView(theTE, vScroll);
- gItem = editField;
- gHandled = true;
- return noErr;
- }
-
- if (!validChar && !isArrow && theChar != CR && theChar != deleteKey ||
- readOnly && !isArrow ||
- theChar == CR && !returnIsLegal)
- {
- SysBeep(0);
- gHandled = true;
- return noErr;
- }
-
- if (validChar || theChar == CR) {
- if ((**theTE).teLength - (selEnd - selStart) + 1 > maxLength) goto exit;
- if (password != nil) {
- BlockMoveData(password + selEnd, password + selStart + 1, pwLen - selEnd + 1);
- *(password + selStart) = theChar;
- gEv->message = '•';
- }
- }
-
- if (theChar == deleteKey && password != nil) {
- if (selStart == selEnd && selStart > 0) selStart--;
- BlockMoveData(password + selEnd, password + selStart, pwLen - selEnd + 1);
- }
-
- if (isArrow) {
- TEArrowKey(theChar, modifiers, theTE, 0, &gPrevEvent, &scrollIntoView);
- if (curItem > 0)
- TEScrollScrollRangeIntoView(theTE, scrollIntoView, scrollIntoView, vScroll);
- gItem = editField;
- gHandled = true;
- } else if (curItem > 0) {
- TEKey(theChar, theTE);
- TEScrollScrollSelectionIntoView(theTE, vScroll);
- gItem = editField;
- gHandled = true;
- }
-
- return noErr;
-
- exit:
-
- StopAlertNumber(kStrNoMoreTyping);
- gHandled = true;
- return noErr;
- }
-
-
-
- /*----------------------------------------------------------------------------
- Command
-
- Handle a command for a dialog window.
-
- Entry: wind = pointer to dialog window.
- menu = the menu.
- item = the item.
- modifiers = modifiers field from event record.
-
- Exit: function result = error code.
- ----------------------------------------------------------------------------*/
-
- static OSErr Command (WindowPtr wind, short menu, short item, short modifiers)
- {
- DialogPeek dPeek;
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TDialogItemInfo *pItemInfo;
- TEHandle theTE;
- char *password;
- short nBullets, editField = 0, pwLen, curItem;
- ControlHandle vScroll;
- Boolean returnIsLegal, pasteOK = true;
- long maxLength, selStart, selEnd;
- unsigned char *p, *pEnd;
- long scrapLen;
- Handle scrap;
- Boolean validChars[256];
- OSErr err = noErr;
- Boolean extraSpaceAddedInFront, extraSpaceDeleted;
- unsigned short teScrpLength;
-
- dPeek = (DialogPeek)wind;
- info = (TWindow**)GetWRefCon(wind);
- itemInfo = (**info).itemInfo;
- curItem = (**info).curItem;
- if (curItem > 0) {
- editField = curItem;
- theTE = (*itemInfo)[curItem-1].theTE;
- } else {
- editField = dPeek->editField + 1;
- theTE = dPeek->textH;
- }
- if (editField > 0) {
- selStart = (**theTE).selStart;
- selEnd = (**theTE).selEnd;
- pItemInfo = &(*itemInfo)[editField-1];
- password = pItemInfo->password;
- if (password != nil) pwLen = strlen(password);
- vScroll = pItemInfo->vScroll;
- maxLength = pItemInfo->maxLength;
- returnIsLegal = pItemInfo->returnIsLegal;
- BlockMoveData(pItemInfo->validChars, validChars, 256);
- }
-
-
- gHandled = true;
- if (menu != kEditMenu) return noErr;
-
- switch (item) {
- case kCutItem:
- case kCopyItem:
- if (password != nil) break;
- if (item == kCutItem) {
- MyTECut(theTE);
- gItem = editField;
- if (curItem > 0) TEScrollScrollSelectionIntoView(theTE, vScroll);
- } else {
- MyTECopy(theTE);
- }
- break;
- case kPasteItem:
- scrapLen = MyTEGetScrapLen();
- if (scrapLen == 0) break;
- if (scrapLen == 0x8000) goto exit1;
- scrap = TEScrapHandle();
- if ((**theTE).teLength - (selEnd - selStart) + scrapLen > maxLength) goto exit1;
- p = (unsigned char*)*scrap;
- pEnd = p + scrapLen;
- while (p < pEnd) {
- if (*p < ' ') {
- if (*p != returnKey || !returnIsLegal) {
- pasteOK = false;
- break;
- }
- } else if (!validChars[*p]) {
- pasteOK = false;
- break;
- }
- p++;
- }
- if (!pasteOK) goto exit2;
- if (password == nil) {
- if (validChars[' ']) {
- MyTEPaste(nil, 0, theTE, maxLength, &extraSpaceAddedInFront);
- } else {
- TEPaste(theTE);
- }
- } else {
- teScrpLength = LMGetTEScrpLength();
- BlockMoveData(password + selEnd,
- password + selStart + teScrpLength,
- pwLen - selEnd + 1);
- BlockMoveData(*LMGetTEScrpHandle(),
- password + selStart,
- teScrpLength);
- nBullets = teScrpLength;
- TEDelete(theTE);
- while (nBullets--) TEInsert("•", 1, theTE);
- }
- gItem = editField;
- if (curItem > 0) TEScrollScrollSelectionIntoView(theTE, vScroll);
- break;
- case kClearItem:
- MyTEDelete(theTE, false, &extraSpaceDeleted);
- gItem = editField;
- if (curItem > 0) TEScrollScrollSelectionIntoView(theTE, vScroll);
- break;
- case kSelectAllItem:
- TESetSelect(0, 0x7fff, theTE);
- break;
- }
-
- return err;
-
- exit1:
-
- StopAlertNumber(kStrScrapTooBig);
- return noErr;
-
- exit2:
-
- StopAlertNumber(kStrScrapBadChar);
- return noErr;
- }
-
-
-
- /*----------------------------------------------------------------------------
- Close
-
- Close a dialog window.
-
- Entry: wind = pointer to dialog window.
-
- Exit: function result = error code.
- ----------------------------------------------------------------------------*/
-
- static OSErr Close (WindowPtr wind)
- {
- TWindow **info;
- TDialogItemInfo **itemInfo;
- short item, numItems;
- TDialogItemInfo *pItemInfo;
-
- gMyCurDialog = nil;
- info = (TWindow**)GetWRefCon(wind);
- itemInfo = (**info).itemInfo;
- numItems = CountDITL(wind);
- MyHLock(itemInfo);
- for (item = 1, pItemInfo = *itemInfo;
- item <= numItems;
- item++, pItemInfo++)
- {
- if (pItemInfo->theTE != nil) TEDispose(pItemInfo->theTE);
- }
- MyDisposeHandle(itemInfo);
- MyDisposeHandle(info);
- DisposeDialog(wind);
- return noErr;
- }
-
-
-
- /*----------------------------------------------------------------------------
- Idle
-
- Handle idle time tasks for a dialog window.
-
- Entry: wind = pointer to dialog window.
-
- Exit: cursorRgn = cursor region for WaitNextEvent mouse moved events
- (not set or used with dialog windows).
- ----------------------------------------------------------------------------*/
-
- static void Idle (WindowPtr wind, RgnHandle cursorRgn)
- {
- DialogPeek dPeek;
- TWindow **info;
- TDialogItemInfo **itemInfo;
- TDialogItemInfo *pItemInfo;
- Point where;
- Boolean setCursorToIBeam = false, password = false;
- short item, itemType, editField = 0;
- Handle itemHandle;
- unsigned long appleMenuFlags, editMenuFlags;
- TEHandle theTE, curTE;
- Boolean readOnly;
- short curItem;
- Rect box;
- Boolean somethingSelected;
-
- info = (TWindow**)GetWRefCon(wind);
- itemInfo = (**info).itemInfo;
- curItem = (**info).curItem;
- dPeek = (DialogPeek)wind;
- if (curItem > 0) {
- editField = curItem;
- curTE = (*itemInfo)[curItem-1].theTE;
- TEIdle(curTE);
- } else {
- editField = dPeek->editField + 1;
- curTE = dPeek->textH;
- }
- if (editField > 0) {
- pItemInfo = &(*itemInfo)[editField-1];
- readOnly = pItemInfo->readOnly;
- password = pItemInfo->password != nil;
- }
-
- GetMouse(&where);
- item = FindDialogItem(wind, where) + 1;
- if (item > 0) {
- theTE = (*itemInfo)[item-1].theTE;
- GetDialogItem(wind, item, &itemType, &itemHandle, &box);
- if ((itemType & 0x7f) == editText) {
- setCursorToIBeam = true;
- } else if (theTE != nil) {
- box = (**theTE).viewRect;
- setCursorToIBeam = PtInRect(where, &box);
- }
- }
- SetCursor(setCursorToIBeam ? &gIBeamCurs : &qd.arrow);
-
- appleMenuFlags = (**info).movableModal ? kAppleOnlyAboutDisabled : kAppleAllDisabled;
- if (editField > 0) {
- editMenuFlags = 0;
- somethingSelected = (**curTE).selEnd > (**curTE).selStart;
- if (somethingSelected) editMenuFlags |= kCopyMask;
- if ((**curTE).teLength > 0) editMenuFlags |= kSelectAllMask;
- if (!readOnly) {
- if (MyTEGetScrapLen() > 0) editMenuFlags |= kPasteMask;
- if (somethingSelected) editMenuFlags |= kCutMask | kClearMask;
- }
- if (password) editMenuFlags &= ~(kCutMask | kCopyMask);
- if (editMenuFlags != 0) editMenuFlags |= kEntireMenuMask;
- SetMenusTo(appleMenuFlags, 0, editMenuFlags, 0, 0, 0);
- } else {
- SetMenusTo(appleMenuFlags, 0, 0, 0, 0, 0);
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- Help
-
- Handle help balloons for a dialog window.
-
- Entry: wind = pointer to dialog window.
- where = current mouse location in local coordinates.
-
- This function doesn't do anything. Help balloons for dialog windows
- are done by the Dialog Manager using 'hdlg' resources.
- ----------------------------------------------------------------------------*/
-
- static void Help (WindowPtr wind, Point where)
- {
- }
-
-
-
- /*----------------------------------------------------------------------------
- InitDialogDispatchTable
-
- Initialize the dispatch table for dialog windows.
- ----------------------------------------------------------------------------*/
-
- void InitDialogDispatchTable (void)
- {
- TDispatch *d;
-
- d = &gDispatch[kDialog];
-
- d->activate = Activate;
- d->update = Update;
- d->mouse = Mouse;
- d->draggable = Draggable;
- d->key = Key;
- d->grow = nil;
- d->zoom = nil;
- d->command = Command;
- d->close = Close;
- d->idle = Idle;
- d->help = Help;
-
- gAutoScrollUPP = NewTEClickLoopProc(AutoScroll);
- gScrollActionUPP = NewControlActionProc(ScrollAction);
- gDialogFilterUPP = NewModalFilterProc(DialogFilter);
- gScrollingTextFieldUserItemUPP = NewUserItemProc(ScrollingTextFieldUserItem);
- gDlgGrayBorderItemUPP = NewUserItemProc(DlgGrayBorderItem);
- gDlgDefaultButtonOutlineItemUPP = NewUserItemProc(DlgDefaultButtonOutlineItem);
- gAEIdleProcUPP = NewAEIdleProc(AEIdleProc);
- }
-